<?php
function shm_put($id, $data)
{
    global $shm_null;
    shmop_write($id, serialize($data).$shm_null, 0);
}

function shm_get($id)
{
    global $shm_size;
    return @unserialize(shmop_read($id, 0, $shm_size));   
}

function shm_getStatus($id, $key)
{
    $array = shm_get($id);
    return $array[$key]['status'];
}

function shm_update($id, $array, $key)
{
    global $lockFile;
    
    flock($lockFile,LOCK_EX);
    $old_array = shm_get($id);
    $old_array[$key] = $array + $old_array[$key];
    shm_put($id,$old_array); 
    flock($lockFile, LOCK_UN);
}

function shm_add($id, $array)
{
    global $lockFile;

    flock($lockFile,LOCK_EX);
    $download_list = shm_get($id);
    $download_list[] = $array;
    shm_put($id, $download_list);
    flock($lockFile, LOCK_UN);
}

?>